<?php

namespace App\Controller\Admin\Content;

use App\Controller\Admin\BaseController;
use App\Service\Content\AdService;
use App\Validator\Admin\Content\AdGroupValidator;
use Hyperf\Di\Annotation\Inject;

class AdGroupController extends BaseController
{

    #[Inject]
    protected AdGroupValidator $adGroupValidator;

    #[Inject]
    protected AdService $adService;

    public function pageList()
    {
        $params = $this->allParams();
        [$va, $page, $ps] = $this->adGroupValidator->pageList($params);
        $lists = $this->adService->adGroupPageList($va, $page, $ps);
        return $this->success($lists);
    }

    public function detail()
    {

    }

    public function add()
    {
        $params = $this->allParams();
        $va = $this->adGroupValidator->add($params);
        [$r, $msg] = $this->adService->addAdGroup($va);
        if ($r) {
            return $this->success(null, $msg);
        }
        return $this->fail($msg);
    }

    public function update()
    {
        $params = $this->allParams();
        $va = $this->adGroupValidator->update($params);
        [$r, $msg] = $this->adService->updateAdGroup(intval($va['id']), $va);
        if ($r) {
            return $this->success(null, $msg);
        }
        return $this->fail($msg);
    }

    public function del()
    {
        $params = $this->allParams();
        $va = $this->adGroupValidator->del($params);
        [$r, $msg] = $this->adService->delGroup($va['ids']);
        if ($r) {
            return $this->success(null, $msg);
        }
        return $this->fail($msg);
    }
}